package com.vchello.service.export;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import com.vchello.bean.user.User;

/**
 * 
 * @author power
 *
 */
public class UserExportService extends ExportService {

	@Override
	public String[] returnColuom() {
		return new String[] { "用户名", "用户类型", "邮箱", "手机", "创建时间", "最后登录时间", "绑定状态"};
	}

	@Override
	public void downLoad(HttpServletResponse response, List<?> list, String[] headers) {
		String fileName = "用户信息";
		//第一步创建workbook  
        HSSFWorkbook wb = new HSSFWorkbook();  
        //第二步创建sheet  
        HSSFSheet sheet = wb.createSheet("身份证错误信息");  
        //第三步创建行row:添加表头0行  
        HSSFRow row = sheet.createRow(0);  
        HSSFCellStyle  style = wb.createCellStyle();      
        style.setAlignment(HSSFCellStyle.ALIGN_CENTER);  //居中  
        //第四步创建单元格  
        HSSFCell cell = row.createCell(0);         //第一个单元格  
        cell.setCellValue("姓名");                  //设定值  
        cell.setCellStyle(style);                   //内容居中  
          
        cell = row.createCell(1);                   //第二个单元格     
        cell.setCellValue("身份证");  
        cell.setCellStyle(style);  
          
        cell = row.createCell(2);                   //第三个单元格    
        cell.setCellValue("错误状态");  
        cell.setCellStyle(style);  
          
        cell = row.createCell(3);                   //第四个单元格    
        cell.setCellValue("错误信息");  
        cell.setCellStyle(style);  
        
        User user0 = new User();
        user0.setUserName("111");
        user0.setPhone("18665690991");
        user0.setStatus(1);
        user0.setType(2);
		User user1 = new User();
		user1.setUserName("111");
		user1.setPhone("18665690991");
		user1.setStatus(1);
		user1.setType(2);
		List<User> users = new ArrayList<User>();
		users.add(user0);
		users.add(user1);
          
        //第五步插入数据  
        for (int i = 0; i < list.size(); i++) {  
            User user = (User) list.get(i);  
            //创建行  
            row = sheet.createRow(i+1);  
            //创建单元格并且添加数据  
            row.createCell(0).setCellValue(user.getUserName());  
            row.createCell(1).setCellValue(user.getPhone());  
            row.createCell(2).setCellValue(user.getStatus());  
            row.createCell(3).setCellValue(user.getType());  
        }  
		
	}

}
